package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        System.out.print("请输入你要删除书籍的名字: ");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();

        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if(bookList.getBook(i).getName().equals(name)){
                int j = i;
                for (; j < bookList.getUsedSize()-1; j++) {
                    Book book = bookList.getBook(j+1);
                    bookList.setBook(j,book);
                }
                bookList.setBook(j,null);
                int n = bookList.getUsedSize();
                bookList.setUsedSize(n-1);
                return;
            }
        }
        System.out.println("该书库不存在这本书");

    }
}
